<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Yuyue extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'yuyue';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'manyi_text',
        'shoptime_text',
        'sex_text',
        'status_text'
    ];
    

    
    public function getManyiList()
    {
        return ['5' => __('Manyi 5'), '4' => __('Manyi 4'), '3' => __('Manyi 3'), '2' => __('Manyi 2'), '1' => __('Manyi 1'), '0' => __('Manyi 0')];
    }

    public function getSexList()
    {
        return ['0' => __('Sex 0'), '1' => __('Sex 1'), '2' => __('Sex 2')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getManyiTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['manyi']) ? $data['manyi'] : '');
        $list = $this->getManyiList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getShoptimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['shoptime']) ? $data['shoptime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setShoptimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
